package com.os.sys.common.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;


/**
 * Created by Administrator on 2017/1/12.
 */
@Service
public class RedisCacheService {

    @Autowired
    RedisTemplate redisTemplate;

    public void set(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public void set(String key, Object value, long minutes) {
        redisTemplate.opsForValue().set(key, value, minutes, TimeUnit.MINUTES);
    }

    public boolean hasKey(String key) {
        return redisTemplate.hasKey(key);
    }

    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public Boolean expire(String key, long minutes) {
        return redisTemplate.expire(key, minutes, TimeUnit.MINUTES);
    }

    public void delete(String key){
        redisTemplate.delete(key);
    }

    public void expireTime(String key, long minutes){
        redisTemplate.expire(key, minutes, TimeUnit.MINUTES);
    }
}
